#!/bin/bash

function getIp {
    ip=$(vagrant ssh -c "hostname -I | python3 -c 'import fileinput; ip=list(fileinput.input())[0].split(\" \")[0].strip(); print(ip)'" $1)
    echo $ip
}

function getAllRunningVMList {
    for vm in $(vagrant status | grep running | awk '{print $1}')
    do
        echo $vm
    done
}

list=$(getAllRunningVMList)

rm -f inventory.list

for entry in $list
do
    ip=$(getIp $entry)
    echo "$entry:$ip" >> inventory.list
done
